// pages/check/management/add/add.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
	name:'',
	type:'',
	price:'',
	time:'',
	remake:'',
	tips:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  console.log(options)
	wx.getStorage({
		key:'uid',
		success:(e)=>{
			console.log(options.id)
			if(options.id!=undefined){
				this.setData({
					remake:options.remake,
					tips:options.tips,
					name:options.name,
					type:options.type,
					time:options.time,
					price:options.price,
					id:options.id
				})
			}
			this.setData({
				uid:e.data.uid
			})
		}
	})
  },
name(e){
	this.setData({
		name:e.detail.value
	})
},
type(e){
	this.setData({
		type:e.detail.value
	})
},
time(e){
	this.setData({
		time:e.detail.value
	})
},
remake(e){
	this.setData({
		remake:e.detail.value
	})
},
price(e){
	this.setData({
		price:e.detail.value
	})
},
tips(e){
	this.setData({
		tips:e.detail.value
	})
},
sure(){
	if(this.data.name!=''&&this.data.type!=''&&this.data.price!=''&&this.data.time!=''&&this.data.remake!=''){
		let a=''
		if(this.data.id!=undefined){
			a=('action=updateServer&id='+this.data.id)
		}else{
			a='action=addServer'
		}
		console.log(a)
		wx.request({
			url:getApp().globalData.chang+a+'&uid='+this.data.uid+'&serName='+this.data.name+'&serType='+this.data.type
			+'&price='+this.data.price+'&gprice='+this.data.time+'&remark='+this.data.remake+'&tips='+this.data.tips,
			success:(e)=>{
				console.log(e)
				if(e.data.code==1){
					wx.navigateBack({
						delta:1
					})
				}else{
					wx.showToast({
						icon:'none',
						title:e.data.msg
					})
				}
			}
		})
	}else{
		console.log(this.data.remake!='')
		wx.showToast({
			icon:'none',
			title:'请正确填写信息'
		})
	}
	
},
})